import { tgxAudioMgr, tgxUIController } from "../../core_tgx/tgx";
import { GameUILayers } from "../../scripts/GameUILayers";
import { UserLocalCache } from "../scripts/UserLocalCache";
import { Layout_UISettings } from "./Layout_UISettings";

export class UISettings extends tgxUIController {
    constructor() {
        super("ui_settings/ui_settings", GameUILayers.POPUP, Layout_UISettings);
    }

    protected onCreated(): void {
        let layout = this.layout as Layout_UISettings;

        layout.sliderMusic.progress = UserLocalCache.inst.musicVolume;
        layout.sliderSound.progress = UserLocalCache.inst.soundVolume;

        this.onButtonEvent(layout.btnClose, () => {
            this.hide();
        });

        this.onSlideEvent(layout.sliderMusic, () => {
            tgxAudioMgr.inst.musicVolume = UserLocalCache.inst.musicVolume = layout.sliderMusic.progress;
        });

        this.onSlideEvent(layout.sliderSound, () => {
            tgxAudioMgr.inst.soundVolume = UserLocalCache.inst.soundVolume = layout.sliderSound.progress;
        });
    }
}


